package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.DeviceDataPageReqDto;
import com.zzyl.nursing.service.IDeviceDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 设备信息Controller
 *
 * @author JQ
 * @date 2025-08-04
 */
@Tag(name = "设备信息")
@RestController
@RequestMapping("/nursing/data")
public class DeviceDataController extends BaseController {
    @Autowired
    private IDeviceDataService deviceDataService;


    /**
     * 查询设备信息列表
     */
    @Operation(summary = "查询设备信息列表")
    @PreAuthorize("@ss.hasPermi('nursing:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceDataPageReqDto dto) {
        return deviceDataService.selectDeviceDataList(dto);
    }


    /**
     * 获取设备信息详细信息
     */
    @Operation(summary = "获取设备信息详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@Parameter(description = "设备信息ID") @PathVariable("id") Long id) {
        return success(deviceDataService.selectDeviceDataById(id));
    }

    /**
     * 新增设备信息
     */
    @Operation(summary = "新增设备信息")
    @PreAuthorize("@ss.hasPermi('nursing:data:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceData deviceData) {
        return toAjax(deviceDataService.insertDeviceData(deviceData));
    }

    /**
     * 修改设备信息
     */
    @Operation(summary = "修改设备信息")
    @PreAuthorize("@ss.hasPermi('nursing:data:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceData deviceData) {
        return toAjax(deviceDataService.updateDeviceData(deviceData));
    }




    @DeleteMapping("/{id}")
    @Operation(summary = "删除设备信息")
    @PreAuthorize("@ss.hasPermi('nursing:data:remove')")
    public R delete(@PathVariable Long id) {
        return deviceDataService.deleteDeviceDataById(id) > 0 ? R.ok(1) : R.fail(0);
    }
}
